﻿using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace LdtJudge.DataEngine.CallInterface.ConfigManager
{
    /// <summary>
    /// 配置操作类
    /// </summary>
    public class ConfigManagerHandle
    {

        private static ConfigManagerHandle _configmangerhandle;
        /// <summary>
        /// 获取配置对象信息
        /// </summary>
        public static ConfigManagerHandle GetConfigManagerHandle
        {
            get => _configmangerhandle;
        }
        /// <summary>
        /// 实例化构造函数
        /// </summary>
        /// <param name="configuration">配置对象</param>
        public ConfigManagerHandle(IConfiguration configuration)
        {
            _configmangerhandle = this;
            IsDeleteWordPath = Convert.ToBoolean(configuration["appSettings:IsDeleteWordPath"]);
            Settingcenter = Convert.ToString(configuration["appSettings:setting_center_address"]);
            Appcode = Convert.ToString(configuration["appSettings:ApplicationCode"]);
            IsLoadLocalDataConfig = Convert.ToBoolean(configuration["appSettings:IsLoadLocalDataConfig"]);
            IsMachine = Convert.ToBoolean(configuration["appSettings:IsMachine"]);
            AnalysisThreadCount = Convert.ToInt32(configuration["appSettings:AnalysisThreadCount"]);
            CaseOptimizeThreadCount = Convert.ToInt32(configuration["appSettings:CaseOptimizeThreadCount"]);
            OtherUnitFiled_daicheng = configuration["appSettings:otherUnitFiled_daicheng"];
            AnalysisRuleTimeSpan = Convert.ToInt32(configuration["appSettings:AnalysisRuleTimeSpan"]);
        }

        ///<summary>
        /// CS_SuitPart_OtherUnit表代称推导
        ///</summary> 
        public string OtherUnitFiled_daicheng { get; set; }

        /// <summary>
        /// 分析线程最大数量
        /// </summary>
        public int AnalysisThreadCount { get; set; }
        /// <summary>
        /// 优选线程最大数量
        /// </summary>
        public int CaseOptimizeThreadCount { get; set; }
        /// <summary>
        /// 本系统入口标签
        /// </summary>
        public enum PlatFormName
        {
            /// <summary>
            /// 工具入口
            /// </summary>
            analysistool = 0,
            /// <summary>
            /// 数据同步API入口
            /// </summary>
            wordparse_analysisapi = 1,
            /// <summary>
            /// 后台分析服务入口
            /// </summary>
            wordparse_analysisservice = 2,
            /// <summary>
            /// 分析公共能力
            /// </summary>
            wordparse_commoncapacitysupport=3
        }


        ///<summary>
        /// 是否进行机器学习分段
        ///</summary> 
        public bool IsMachine { get; set; }

        ///// <summary>
        ///// 获取是否启用日志写入;
        ///// The trace log switch
        ///// </summary>
        //public string FatalLogSwitch { get; }

        ///// <summary>
        ///// 流转日志是否开启
        ///// </summary>
        //public  string FlowLog { get; } 
        ///// <summary>
        ///// 异常日志开关
        ///// </summary>
        //public  string ExceptionLog { get; } 

        ///// <summary>
        ///// 正则日志的开关
        ///// </summary>
        //public  bool RegexLogSwitch { get; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public bool IsDeleteWordPath { get; }
        /// <summary>
        /// 配置中心地址
        /// </summary>
        public string Settingcenter { get; }
        /// <summary>
        /// 应用程序Code
        /// </summary>
        public string Appcode { get; }
        /// <summary>
        /// 是否调用本地配置
        /// </summary>
        public bool IsLoadLocalDataConfig { get; }
        /// <summary>
        /// 将文件对象进行用JSON转换为String字符串
        /// Returns the json string.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns>System.String.</returns>
        public static string ReturnJsonString(object obj)
        {
            return JsonConvert.SerializeObject(obj);
        }

        /// <summary>
        /// 将Json字符串转换为传入对象 
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns>System.String.</returns>
        public static T ReturnJsonToModel<T>(string obj)
        {
            return JsonConvert.DeserializeObject<T>(obj);
        }

        /// <summary>
        /// 正则超时设置秒为单位
        /// </summary>
        public int AnalysisRuleTimeSpan { get; }
    }
}
